package xyz.eden.cloud.common.web.tool;

import org.springframework.util.AntPathMatcher;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * PathMatcherTool
 */
public class PathMatcherTool {

    public static boolean isMatch(String path, List<String> patternList) {
        return Optional.ofNullable(patternList).orElse(Collections.emptyList())
                .stream().anyMatch(pattern -> {
                    return isMatch(pattern, path);
                });
    }


    public static boolean isMatch(String pattern, String path) {
        AntPathMatcher matcher = new AntPathMatcher();
        return matcher.match(pattern, path);
    }
}
